package com.baizhi.wd.action;

import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.Person;
import com.baizhi.wd.service.TelbookService;
import com.baizhi.wd.service.TelbookServiceImpl;

public class UpdateSaveAction extends HttpServlet {
	public void service(HttpServletRequest request,HttpServletResponse response) throws IOException{
		try{
			//1获取client信息
			request.setCharacterEncoding("utf-8");
			String idd = request.getParameter("id");
			int id = Integer.parseInt(idd);
			String username = request.getParameter("username");
			String mobile = request.getParameter("mobile");
			String telphone = request.getParameter("telphone");
			String email = request.getParameter("email");
			String city = request.getParameter("city");
			String birthday = request.getParameter("birthday");	
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			java.util.Date utilbirthday = sdf.parse(birthday);
			
			Person per = new Person(id,username,mobile,telphone,email,city,utilbirthday);
			//2调用业务层的修改方法
			TelbookService ts = new TelbookServiceImpl();
			ts.changePersonMessage(per);
			//3跳转到查所有--重定向
			response.sendRedirect("/telbook_2/per/queryAllAction");
		}catch(Exception e){
			response.sendRedirect("/telbook_2/catchError.html");
			e.printStackTrace();
			
		}
	}
}
